package com.machuxin.course.patterns.proxy.jdklib.impl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxyHandler2 implements MInvocationHandler {

    private Object object;

    public Object getInstance(Object o) {
        this.object = o;
        Class<?> clazz = o.getClass();
        return MProxy.newProxyInstance(new MClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("买房前准备");
        Object result = method.invoke(object, args);
        System.out.println("买房后装修");
        return result;
    }
}
